{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<!DOCTYPE html><!--STATUS OK-->\r\n",
      "<html>\r\n",
      "<head>\r\n",
      "\t<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\r\n",
      "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge\">\r\n",
      "\t<link rel=\"dns-prefetch\" href=\"//s1.bdstatic.com\"/>\r\n",
      "\t<link rel=\"dns-prefetch\" href=\"//t1.baidu.com\"/>\r\n",
      "\t<link rel=\"dns-prefetch\" href=\"//t2.baidu.com\"/>\r\n",
      "\t<link rel=\"dns-prefetch\" href=\"//t3.baidu.com\"/>\r\n",
      "\t<link rel=\"dns-prefetch\" href=\"//t10.baidu.com\"/>\r\n",
      "\t<link rel=\"dns-prefetch\" href=\"//t11.baidu.com\"/>\r\n",
      "\t<link rel=\"dns-prefetch\" href=\"//t12.baidu.com\"/>\r\n",
      "\t<link rel=\"dns-prefetch\" href=\"//b1.bdstatic.com\"/>\r\n",
      "\t<title>百度一下，你就知道</title>\r\n",
      "\t<link href=\"http://s1.bdstatic.com/r/www/cache/static/home/css/index.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n",
      "\t<!--[if lte IE 8]><style index=\"index\" >#content{height:480px\\9}#m{top:260px\\9}</style><![endif]-->\r\n",
      "\t<!--[if IE 8]><style index=\"index\" >#u1 a.mnav,#u1 a.mnav:visited{font-family:simsun}</style><![endif]-->\r\n",
      "\t<script>var hashMatch = document.location.href.match(/#+(.*wd=[^&].+)/);if (hashMatch && hashMatch[0] && hashMatch[1]) {document.location.replace(\"http://\"+location.host+\"/s?\"+hashMatch[1]);}var ns_c = function(){};</script>\r\n",
      "\t<script>function h(obj){obj.style.behavior='url(#default#homepage)';var a = obj.setHomePage('//www.baidu.com/');}</script>\r\n",
      "\t<noscript><meta http-equiv=\"refresh\" content=\"0; url=/baidu.html?from=noscript\"/></noscript>\r\n",
      "\t<script>window._ASYNC_START=new Date().getTime();</script>\r\n",
      "</head>\r\n",
      "<body link=\"#0000cc\"><div id=\"wrapper\" style=\"display:none;\"><div id=\"u\"><a href=\"//www.baidu.com/gaoji/preferences.html\"  onmousedown=\"return user_c({'fm':'set','tab':'setting','login':'0'})\">搜索设置</a>|<a id=\"btop\" href=\"/\"  onmousedown=\"return user_c({'fm':'set','tab':'index','login':'0'})\">百度首页</a>|<a id=\"lb\" href=\"https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F\" onclick=\"return false;\"  onmousedown=\"return user_c({'fm':'set','tab':'login'})\">登录</a><a href=\"https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F\"  onmousedown=\"return user_c({'fm':'set','tab':'reg'})\" target=\"_blank\" class=\"reg\">注册</a></div><div id=\"head\"><div class=\"s_nav\"><a href=\"/\" class=\"s_logo\" onmousedown=\"return c({'fm':'tab','tab':'logo'})\"><img src=\"//www.baidu.com/img/baidu_jgylogo3.gif\" width=\"117\" height=\"38\" border=\"0\" alt=\"到百度首页\" title=\"到百度首页\"></a><div class=\"s_tab\" id=\"s_tab\"><a href=\"http://news.baidu.com/ns?cl=2&rn=20&tn=news&word=\" wdfield=\"word\"  onmousedown=\"return c({'fm':'tab','tab':'news'})\">新闻</a>&#12288;<b>网页</b>&#12288;<a href=\"http://tieba.baidu.com/f?kw=&fr=wwwt\" wdfield=\"kw\"  onmousedown=\"return c({'fm':'tab','tab':'tieba'})\">贴吧</a>&#12288;<a href=\"http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikaslist&rn=10&word=&fr=wwwt\" wdfield=\"word\"  onmousedown=\"return c({'fm':'tab','tab':'zhidao'})\">知道</a>&#12288;<a href=\"http://music.baidu.com/search?fr=ps&key=\" wdfield=\"key\"  onmousedown=\"return c({'fm':'tab','tab':'music'})\">音乐</a>&#12288;<a href=\"http://image.baidu.com/i?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&word=\" wdfield=\"word\"  onmousedown=\"return c({'fm':'tab','tab':'pic'})\">图片</a>&#12288;<a href=\"http://v.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=25&word=\" wdfield=\"word\"   onmousedown=\"return c({'fm':'tab','tab':'video'})\">视频</a>&#12288;<a href=\"http://map.baidu.com/m?word=&fr=ps01000\" wdfield=\"word\"  onmousedown=\"return c({'fm':'tab','tab':'map'})\">地图</a>&#12288;<a href=\"http://wenku.baidu.com/search?word=&lm=0&od=0\" wdfield=\"word\"  onmousedown=\"return c({'fm':'tab','tab':'wenku'})\">文库</a>&#12288;<a href=\"//www.baidu.com/more/\"  onmousedown=\"return c({'fm':'tab','tab':'more'})\">更多»</a></div></div><form id=\"form\" name=\"f\" action=\"/s\" class=\"fm\" ><input type=\"hidden\" name=\"ie\" value=\"utf-8\"><input type=\"hidden\" name=\"f\" value=\"8\"><input type=\"hidden\" name=\"rsv_bp\" value=\"1\"><span class=\"bg s_ipt_wr\"><input name=\"wd\" id=\"kw\" class=\"s_ipt\" value=\"\" maxlength=\"100\"></span><span class=\"bg s_btn_wr\"><input type=\"submit\" id=\"su\" value=\"百度一下\" class=\"bg s_btn\" onmousedown=\"this.className='bg s_btn s_btn_h'\" onmouseout=\"this.className='bg s_btn'\"></span><span class=\"tools\"><span id=\"mHolder\"><div id=\"mCon\"><span>输入法</span></div><ul id=\"mMenu\"><li><a href=\"javascript:;\" name=\"ime_hw\">手写</a></li><li><a href=\"javascript:;\" name=\"ime_py\">拼音</a></li><li class=\"ln\"></li><li><a href=\"javascript:;\" name=\"ime_cl\">关闭</a></li></ul></span><span class=\"shouji\"><strong>推荐&nbsp;:&nbsp;</strong><a href=\"http://w.x.baidu.com/go/mini/8/10000020\" onmousedown=\"return ns_c({'fm':'behs','tab':'bdbrowser'})\">百度浏览器，打开网页快2秒！</a></span></span></form></div><div id=\"content\"><div id=\"u1\"><a href=\"http://news.baidu.com\" name=\"tj_trnews\" class=\"mnav\">新闻</a><a href=\"http://www.hao123.com\" name=\"tj_trhao123\" class=\"mnav\">hao123</a><a href=\"http://map.baidu.com\" name=\"tj_trmap\" class=\"mnav\">地图</a><a href=\"http://v.baidu.com\" name=\"tj_trvideo\" class=\"mnav\">视频</a><a href=\"http://tieba.baidu.com\" name=\"tj_trtieba\" class=\"mnav\">贴吧</a><a href=\"https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F\" name=\"tj_login\" id=\"lb\" onclick=\"return false;\">登录</a><a href=\"//www.baidu.com/gaoji/preferences.html\" name=\"tj_settingicon\" id=\"pf\">设置</a><a href=\"//www.baidu.com/more/\" name=\"tj_briicon\" id=\"bri\">更多产品</a></div><div id=\"m\"><p id=\"lg\"><img src=\"//www.baidu.com/img/bd_logo.png\" width=\"270\" height=\"129\"></p><p id=\"nv\"><a href=\"http://news.baidu.com\">新&nbsp;闻</a>　<b>网&nbsp;页</b>　<a href=\"http://tieba.baidu.com\">贴&nbsp;吧</a>　<a href=\"http://zhidao.baidu.com\">知&nbsp;道</a>　<a href=\"http://music.baidu.com\">音&nbsp;乐</a>　<a href=\"http://image.baidu.com\">图&nbsp;片</a>　<a href=\"http://v.baidu.com\">视&nbsp;频</a>　<a href=\"http://map.baidu.com\">地&nbsp;图</a></p><div id=\"fm\"><form id=\"form1\" name=\"f1\" action=\"/s\" class=\"fm\"><span class=\"bg s_ipt_wr\"><input type=\"text\" name=\"wd\" id=\"kw1\" maxlength=\"100\" class=\"s_ipt\"></span><input type=\"hidden\" name=\"rsv_bp\" value=\"0\"><input type=hidden name=ch value=\"\"><input type=hidden name=tn value=\"baidu\"><input type=hidden name=bar value=\"\"><input type=\"hidden\" name=\"rsv_spt\" value=\"3\"><input type=\"hidden\" name=\"ie\" value=\"utf-8\"><span class=\"bg s_btn_wr\"><input type=\"submit\" value=\"百度一下\" id=\"su1\" class=\"bg s_btn\" onmousedown=\"this.className='bg s_btn s_btn_h'\" onmouseout=\"this.className='bg s_btn'\"></span></form><span class=\"tools\"><span id=\"mHolder1\"><div id=\"mCon1\"><span>输入法</span></div></span></span><ul id=\"mMenu1\"><div class=\"mMenu1-tip-arrow\"><em></em><ins></ins></div><li><a href=\"javascript:;\" name=\"ime_hw\">手写</a></li><li><a href=\"javascript:;\" name=\"ime_py\">拼音</a></li><li class=\"ln\"></li><li><a href=\"javascript:;\" name=\"ime_cl\">关闭</a></li></ul></div><p id=\"lk\"><a href=\"http://baike.baidu.com\">百科</a>　<a href=\"http://wenku.baidu.com\">文库</a>　<a href=\"http://www.hao123.com\">hao123</a><span>&nbsp;|&nbsp;<a href=\"//www.baidu.com/more/\">更多&gt;&gt;</a></span></p><p id=\"lm\"></p></div></div><div id=\"ftCon\"><div id=\"ftConw\"><p id=\"lh\"><a id=\"seth\" onClick=\"h(this)\" href=\"/\" onmousedown=\"return ns_c({'fm':'behs','tab':'homepage','pos':0})\">把百度设为主页</a><a id=\"setf\" href=\"//www.baidu.com/cache/sethelp/index.html\" onmousedown=\"return ns_c({'fm':'behs','tab':'favorites','pos':0})\" target=\"_blank\">把百度设为主页</a><a onmousedown=\"return ns_c({'fm':'behs','tab':'tj_about'})\" href=\"http://home.baidu.com\">关于百度</a><a onmousedown=\"return ns_c({'fm':'behs','tab':'tj_about_en'})\" href=\"http://ir.baidu.com\">About Baidu</a></p><p id=\"cp\">&copy;2018&nbsp;Baidu&nbsp;<a href=\"/duty/\" name=\"tj_duty\">使用百度前必读</a>&nbsp;京ICP证030173号&nbsp;<img src=\"http://s1.bdstatic.com/r/www/cache/static/global/img/gs_237f015b.gif\"></p></div></div><div id=\"wrapper_wrapper\"></div></div><div class=\"c-tips-container\" id=\"c-tips-container\"></div>\r\n",
      "<script>window.__async_strategy=2;</script>\r\n",
      "<script>var bds={se:{},su:{urdata:[],urSendClick:function(){}},util:{},use:{},comm : {domain:\"http://www.baidu.com\",ubsurl : \"http://sclick.baidu.com/w.gif\",tn:\"baidu\",queryEnc:\"\",queryId:\"\",inter:\"\",templateName:\"baidu\",sugHost : \"http://suggestion.baidu.com/su\",query : \"\",qid : \"\",cid : \"\",sid : \"\",indexSid : \"\",stoken : \"\",serverTime : \"\",user : \"\",username : \"\",loginAction : [],useFavo : \"\",pinyin : \"\",favoOn : \"\",curResultNum:\"\",rightResultExist:false,protectNum:0,zxlNum:0,pageNum:1,pageSize:10,newindex:0,async:1,maxPreloadThread:5,maxPreloadTimes:10,preloadMouseMoveDistance:5,switchAddMask:false,isDebug:false,ishome : 1},_base64:{domain : \"http://b1.bdstatic.com/\",b64Exp : -1,pdc : 0}};var name,navigate,al_arr=[];var selfOpen = window.open;eval(\"var open = selfOpen;\");var isIE=navigator.userAgent.indexOf(\"MSIE\")!=-1&&!window.opera;var E = bds.ecom= {};bds.se.mon = {'loadedItems':[],'load':function(){},'srvt':-1};try {bds.se.mon.srvt = parseInt(document.cookie.match(new RegExp(\"(^| )BDSVRTM=([^;]*)(;|$)\"))[2]);document.cookie=\"BDSVRTM=;expires=Sat, 01 Jan 2000 00:00:00 GMT\"; }catch(e){}</script>\r\n",
      "<script>if(!location.hash.match(/[^a-zA-Z0-9]wd=/)){document.getElementById(\"ftCon\").style.display='block';document.getElementById(\"u1\").style.display='block';document.getElementById(\"content\").style.display='block';document.getElementById(\"wrapper\").style.display='block';setTimeout(function(){try{document.getElementById(\"kw1\").focus();document.getElementById(\"kw1\").parentNode.className += ' iptfocus';}catch(e){}},0);}</script>\r\n",
      "<script type=\"text/javascript\" src=\"http://s1.bdstatic.com/r/www/cache/static/jquery/jquery-1.10.2.min_f2fb5194.js\"></script>\r\n",
      "<script>(function(){var index_content = $('#content');var index_foot= $('#ftCon');var index_css= $('head [index]');var index_u= $('#u1');var result_u= $('#u');var wrapper=$(\"#wrapper\");window.index_on=function(){index_css.insertAfter(\"meta:eq(0)\");result_common_css.remove();result_aladdin_css.remove();result_sug_css.remove();index_content.show();index_foot.show();index_u.show();result_u.hide();wrapper.show();if(bds.su&&bds.su.U&&bds.su.U.homeInit){bds.su.U.homeInit();}setTimeout(function(){try{$('#kw1').get(0).focus();window.sugIndex.start();}catch(e){}},0);if(typeof initIndex=='function'){initIndex();}};window.index_off=function(){index_css.remove();index_content.hide();index_foot.hide();index_u.hide();result_u.show();result_aladdin_css.insertAfter(\"meta:eq(0)\");result_common_css.insertAfter(\"meta:eq(0)\");result_sug_css.insertAfter(\"meta:eq(0)\");wrapper.show();};})();</script>\r\n",
      "<script>window.__switch_add_mask=1;</script>\r\n",
      "<script type=\"text/javascript\" src=\"http://s1.bdstatic.com/r/www/cache/static/global/js/instant_search_newi_redirect1_20bf4036.js\"></script>\r\n",
      "<script>initPreload();$(\"#u,#u1\").delegate(\"#lb\",'click',function(){try{bds.se.login.open();}catch(e){}});if(navigator.cookieEnabled){document.cookie=\"NOJS=;expires=Sat, 01 Jan 2000 00:00:00 GMT\";}</script>\r\n",
      "<script>$(function(){for(i=0;i<3;i++){u($($('.s_ipt_wr')[i]),$($('.s_ipt')[i]),$($('.s_btn_wr')[i]),$($('.s_btn')[i]));}function u(iptwr,ipt,btnwr,btn){if(iptwr && ipt){iptwr.on('mouseover',function(){iptwr.addClass('ipthover');}).on('mouseout',function(){iptwr.removeClass('ipthover');}).on('click',function(){ipt.focus();});ipt.on('focus',function(){iptwr.addClass('iptfocus');}).on('blur',function(){iptwr.removeClass('iptfocus');}).on('render',function(e){var $s = iptwr.parent().find('.bdsug');var l = $s.find('li').length;if(l>=5){$s.addClass('bdsugbg');}else{$s.removeClass('bdsugbg');}});}if(btnwr && btn){btnwr.on('mouseover',function(){btn.addClass('btnhover');}).on('mouseout',function(){btn.removeClass('btnhover');});}}});</script>\r\n",
      "<script type=\"text/javascript\" src=\"http://s1.bdstatic.com/r/www/cache/static/home/js/bri_7f1fa703.js\"></script>\r\n",
      "<script>(function(){var _init=false;window.initIndex=function(){if(_init){return;}_init=true;var w=window,d=document,n=navigator,k=d.f1.wd,a=d.getElementById(\"nv\").getElementsByTagName(\"a\"),isIE=n.userAgent.indexOf(\"MSIE\")!=-1&&!window.opera;(function(){if(/q=([^&]+)/.test(location.search)){k.value=decodeURIComponent(RegExp[\"\\x241\"])}})();(function(){var u = G(\"u1\").getElementsByTagName(\"a\"), nv = G(\"nv\").getElementsByTagName(\"a\"), lk = G(\"lk\").getElementsByTagName(\"a\"), un = \"\";var tj_nv = [\"news\",\"tieba\",\"zhidao\",\"mp3\",\"img\",\"video\",\"map\"];var tj_lk = [\"baike\",\"wenku\",\"hao123\",\"more\"];un = bds.comm.user == \"\" ? \"\" : bds.comm.user;function _addTJ(obj){addEV(obj, \"mousedown\", function(e){var e = e || window.event;var target = e.target || e.srcElement;if(target.name){ns_c({'fm':'behs','tab':target.name,'un':encodeURIComponent(un)});}});}for(var i = 0; i < u.length; i++){_addTJ(u[i]);}for(var i = 0; i < nv.length; i++){nv[i].name = 'tj_' + tj_nv[i];}for(var i = 0; i < lk.length; i++){lk[i].name = 'tj_' + tj_lk[i];}})();(function() {var links = {'tj_news': ['word', 'http://news.baidu.com/ns?tn=news&cl=2&rn=20&ct=1&ie=utf-8'],'tj_tieba': ['kw', 'http://tieba.baidu.com/f?ie=utf-8'],'tj_zhidao': ['word', 'http://zhidao.baidu.com/search?pn=0&rn=10&lm=0'],'tj_mp3': ['key', 'http://music.baidu.com/search?fr=ps&ie=utf-8'],'tj_img': ['word', 'http://image.baidu.com/i?ct=201326592&cl=2&nc=1&lm=-1&st=-1&tn=baiduimage&istype=2&fm=&pv=&z=0&ie=utf-8'],'tj_video': ['word', 'http://video.baidu.com/v?ct=301989888&s=25&ie=utf-8'],'tj_map': ['wd', 'http://map.baidu.com/?newmap=1&ie=utf-8&s=s'],'tj_baike': ['word', 'http://baike.baidu.com/search/word?pic=1&sug=1&enc=utf8'],'tj_wenku': ['word', 'http://wenku.baidu.com/search?ie=utf-8']};var domArr = [G('nv'), G('lk'),G('cp')],kw = G('kw1');for (var i = 0, l = domArr.length; i < l; i++) {domArr[i].onmousedown = function(e) {e = e || window.event;var target = e.target || e.srcElement,name = target.getAttribute('name'),items = links[name],reg = new RegExp('^\\\\s+|\\\\s+\\x24'),key = kw.value.replace(reg, '');if (items) {if (key.length > 0) {var wd = items[0], url = items[1],url = url + ( name === 'tj_map' ? encodeURIComponent('&' + wd + '=' + key) : ( ( url.indexOf('?') > 0 ? '&' : '?' ) + wd + '=' + encodeURIComponent(key) ) );target.href = url;} else {target.href = target.href.match(new RegExp('^http:\\/\\/.+\\.baidu\\.com'))[0];}}name && ns_c({'fm': 'behs','tab': name,'query': encodeURIComponent(key),'un': encodeURIComponent(bds.comm.user || '') });};}})();};if(window.pageState==0){initIndex();}})();document.cookie = 'IS_STATIC=1;expires=' + new Date(new Date().getTime() + 10*60*1000).toGMTString();</script>\r\n",
      "</body></html>\r\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#1. epoll并不代表一定比select好\n",
    "# 在并发高的情况下，连接活跃度不是很高， epoll比select\n",
    "# 并发性不高，同时连接很活跃， select比epoll好\n",
    "\n",
    "#通过非阻塞io实现http请求\n",
    "\n",
    "import socket\n",
    "from urllib.parse import urlparse\n",
    "\n",
    "\n",
    "#使用非阻塞io完成http请求\n",
    "\n",
    "def get_url(url):\n",
    "    #通过socket请求html\n",
    "    url = urlparse(url)\n",
    "    host = url.netloc\n",
    "    path = url.path\n",
    "    if path == \"\":\n",
    "        path = \"/\"\n",
    "\n",
    "    #建立socket连接\n",
    "    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",
    "    client.setblocking(False)\n",
    "    try:\n",
    "        client.connect((host, 80)) #阻塞不会消耗cpu\n",
    "    except BlockingIOError as e:\n",
    "        pass\n",
    "\n",
    "    #不停的询问连接是否建立好， 需要while循环不停的去检查状态\n",
    "    #做计算任务或者再次发起其他的连接请求\n",
    "\n",
    "    while True:\n",
    "        try:\n",
    "            client.send(\"GET {} HTTP/1.1\\r\\nHost:{}\\r\\nConnection:close\\r\\n\\r\\n\".format(path, host).encode(\"utf8\"))\n",
    "            break\n",
    "        except OSError as e:\n",
    "            pass\n",
    "\n",
    "\n",
    "    data = b\"\"\n",
    "    while True:\n",
    "        try:\n",
    "            d = client.recv(1024)\n",
    "        except BlockingIOError as e:\n",
    "            continue\n",
    "        if d:\n",
    "            data += d\n",
    "        else:\n",
    "            break\n",
    "\n",
    "    data = data.decode(\"utf8\")\n",
    "    html_data = data.split(\"\\r\\n\\r\\n\")[1]\n",
    "    print(html_data)\n",
    "    client.close()\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    get_url(\"http://www.baidu.com\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 使用select 多路复用 提升http请求性能"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"detail\":\"未找到。\"}\n",
      "{\"id\":6,\"category\":{\"id\":130,\"sub_cat\":[],\"name\":\"茄果类\",\"code\":\"qgl\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/4_P_1448945381985.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/4_P_1448945381013.jpg\"}],\"goods_sn\":\"\",\"name\":\"乌拉圭进口牛肉卷特级肥牛卷\",\"click_num\":4228,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":90.0,\"shop_price\":75.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/4_P_1448945381985.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":1,\"category\":{\"id\":129,\"sub_cat\":[],\"name\":\"根茎类\",\"code\":\"gjl\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/1_P_1449024889889.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/1_P_1449024889264.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/1_P_1449024889726.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/1_P_1449024889018.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/1_P_1449024889287.jpg\"}],\"goods_sn\":\"\",\"name\":\"新鲜水果甜蜜香脆单果约800克\",\"click_num\":7197,\"sold_num\":0,\"fav_num\":1,\"goods_num\":-17,\"market_price\":232.0,\"shop_price\":156.0,\"goods_brief\":\"食用百香果可以增加胃部饱腹感，减少余热量的摄入，还可以吸附胆固醇和胆汁之类有机分子，抑制人体对脂肪的吸收。因此，长期食用有利于改善人体营养吸收结构，降低体内脂肪，塑造健康优美体态。\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/1_P_1449024889889.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:52\"}\n",
      "{\"id\":18,\"category\":{\"id\":138,\"sub_cat\":[],\"name\":\"葡萄酒\",\"code\":\"ptj\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":133},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/46_P_1448946598711.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/46_P_1448946598301.jpg\"}],\"goods_sn\":\"\",\"name\":\"双响炮洋酒JimBeamwhiskey美国白占边\",\"click_num\":4025,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":38.0,\"shop_price\":28.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/46_P_1448946598711.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:54\"}\n",
      "{\"id\":14,\"category\":{\"id\":130,\"sub_cat\":[],\"name\":\"茄果类\",\"code\":\"qgl\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/images/201705/goods_img/53_P_1495068879687.jpg\"}],\"goods_sn\":\"\",\"name\":\"帐篷出租\",\"click_num\":4054,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":120.0,\"shop_price\":100.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/53_P_1495068879687.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:54\"}\n",
      "{\"id\":13,\"category\":{\"id\":121,\"sub_cat\":[{\"id\":122,\"sub_cat\":[],\"name\":\"松花蛋/咸鸭蛋\",\"code\":\"xhd_xyd\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":121},{\"id\":123,\"sub_cat\":[],\"name\":\"鸡蛋\",\"code\":\"jd\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":121}],\"name\":\"蛋制品\",\"code\":\"dzp\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/5_P_1448945270390.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/5_P_1448945270067.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/5_P_1448945270432.jpg\"}],\"goods_sn\":\"\",\"name\":\"澳洲进口安格斯牛切片上脑牛排1000g\",\"click_num\":4035,\"sold_num\":0,\"fav_num\":0,\"goods_num\":-1,\"market_price\":144.0,\"shop_price\":120.0,\"goods_brief\":\"澳大利亚是国际公认的没有疯牛病和口蹄疫的国家。为了保持澳大利亚产品的高标准，澳大利亚牛肉业和各级政府共同努力简历了严格的标准和体系，以保证生产的整体化和产品的可追溯性\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/5_P_1448945270390.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:54\"}\n",
      "{\"id\":3,\"category\":{\"id\":124,\"sub_cat\":[{\"id\":125,\"sub_cat\":[],\"name\":\"生菜\",\"code\":\"sc\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":124},{\"id\":126,\"sub_cat\":[],\"name\":\"菠菜\",\"code\":\"bc\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":124},{\"id\":127,\"sub_cat\":[],\"name\":\"圆椒\",\"code\":\"yj\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":124},{\"id\":128,\"sub_cat\":[],\"name\":\"西兰花\",\"code\":\"xlh\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":124}],\"name\":\"叶菜类\",\"code\":\"ycl\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/7_P_1448945104883.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/7_P_1448945104734.jpg\"}],\"goods_sn\":\"\",\"name\":\"酣畅家庭菲力牛排10片澳洲生鲜牛肉团购套餐\",\"click_num\":4532,\"sold_num\":0,\"fav_num\":0,\"goods_num\":-1,\"market_price\":286.0,\"shop_price\":238.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/7_P_1448945104883.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":8,\"category\":{\"id\":116,\"sub_cat\":[{\"id\":117,\"sub_cat\":[],\"name\":\"参鲍\",\"code\":\"cb\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":118,\"sub_cat\":[],\"name\":\"鱼\",\"code\":\"yu\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":119,\"sub_cat\":[],\"name\":\"虾\",\"code\":\"xia\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":120,\"sub_cat\":[],\"name\":\"蟹/贝\",\"code\":\"xb\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116}],\"name\":\"海鲜水产\",\"code\":\"hxsc\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/11_P_1448944388277.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/11_P_1448944388034.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/11_P_1448944388201.jpg\"}],\"goods_sn\":\"\",\"name\":\"澳洲进口120天谷饲牛仔骨4份原味生鲜\",\"click_num\":4115,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":31.0,\"shop_price\":26.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/11_P_1448944388277.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":7,\"category\":{\"id\":132,\"sub_cat\":[],\"name\":\"进口生鲜\",\"code\":\"jksx\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/8_P_1448945032810.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/8_P_1448945032646.jpg\"}],\"goods_sn\":\"\",\"name\":\"五星眼肉牛排套餐8片装原味原切生鲜牛肉\",\"click_num\":4136,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":150.0,\"shop_price\":125.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/8_P_1448945032810.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":5,\"category\":{\"id\":116,\"sub_cat\":[{\"id\":117,\"sub_cat\":[],\"name\":\"参鲍\",\"code\":\"cb\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":118,\"sub_cat\":[],\"name\":\"鱼\",\"code\":\"yu\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":119,\"sub_cat\":[],\"name\":\"虾\",\"code\":\"xia\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":120,\"sub_cat\":[],\"name\":\"蟹/贝\",\"code\":\"xb\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116}],\"name\":\"海鲜水产\",\"code\":\"hxsc\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/10_P_1448944572085.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/10_P_1448944572532.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/10_P_1448944572872.jpg\"}],\"goods_sn\":\"\",\"name\":\"内蒙新鲜牛肉1斤清真生鲜牛肉火锅食材\",\"click_num\":4228,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":106.0,\"shop_price\":88.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/10_P_1448944572085.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":4,\"category\":{\"id\":129,\"sub_cat\":[],\"name\":\"根茎类\",\"code\":\"gjl\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/47_P_1448946213263.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/47_P_1448946213157.jpg\"}],\"goods_sn\":\"\",\"name\":\"日本蒜蓉粉丝扇贝270克6只装\",\"click_num\":4489,\"sold_num\":0,\"fav_num\":-1,\"goods_num\":0,\"market_price\":156.0,\"shop_price\":108.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/47_P_1448946213263.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":15,\"category\":{\"id\":146,\"sub_cat\":[{\"id\":147,\"sub_cat\":[],\"name\":\"白兰地\",\"code\":\"bld\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":146},{\"id\":148,\"sub_cat\":[],\"name\":\"威士忌\",\"code\":\"wsj\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":146}],\"name\":\"红酒\",\"code\":\"hj\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":133},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/16_P_1448947194687.jpg\"}],\"goods_sn\":\"\",\"name\":\"52度茅台集团国隆双喜酒500mlx6\",\"click_num\":4343,\"sold_num\":0,\"fav_num\":0,\"goods_num\":-5,\"market_price\":23.0,\"shop_price\":19.0,\"goods_brief\":\"贵州茅台酒厂（集团）保健酒业有限公司生产，是以“龙”字打头的酒水。中国龙文化上下8000年，源远而流长，龙的形象是一种符号、一种意绪、一种血肉相联的情感。\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/16_P_1448947194687.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:54\"}\n",
      "{\"id\":10,\"category\":{\"id\":129,\"sub_cat\":[],\"name\":\"根茎类\",\"code\":\"gjl\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/9_P_1448944791617.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/9_P_1448944791129.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/9_P_1448944791077.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/9_P_1448944791229.jpg\"}],\"goods_sn\":\"\",\"name\":\"爱食派内蒙古呼伦贝尔冷冻生鲜牛腱子肉1000g\",\"click_num\":4024,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":202.0,\"shop_price\":168.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/9_P_1448944791617.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":17,\"category\":{\"id\":141,\"sub_cat\":[{\"id\":142,\"sub_cat\":[],\"name\":\"其他品牌\",\"code\":\"qtpp\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":141},{\"id\":143,\"sub_cat\":[],\"name\":\"黄酒\",\"code\":\"hj\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":141},{\"id\":144,\"sub_cat\":[],\"name\":\"养生酒\",\"code\":\"ysj\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":141}],\"name\":\"其他酒品\",\"code\":\"qtjp\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":133},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/12_P_1448947547989.jpg\"}],\"goods_sn\":\"\",\"name\":\"53度茅台仁酒500ml\",\"click_num\":3987,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":190.0,\"shop_price\":158.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/12_P_1448947547989.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:54\"}\n",
      "{\"id\":16,\"category\":{\"id\":145,\"sub_cat\":[],\"name\":\"饮料/水\",\"code\":\"yls\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":133},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/14_P_1448947354031.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/14_P_1448947354433.jpg\"}],\"goods_sn\":\"\",\"name\":\"52度水井坊臻酿八號500ml\",\"click_num\":4088,\"sold_num\":0,\"fav_num\":0,\"goods_num\":-3,\"market_price\":43.0,\"shop_price\":36.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/14_P_1448947354031.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:54\"}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"id\":19,\"category\":{\"id\":145,\"sub_cat\":[],\"name\":\"饮料/水\",\"code\":\"yls\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":133},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/21_P_1448946793276.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/21_P_1448946793153.jpg\"}],\"goods_sn\":\"\",\"name\":\"西夫拉姆进口洋酒小酒版\",\"click_num\":3973,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":55.0,\"shop_price\":46.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/21_P_1448946793276.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:54\"}\n",
      "{\"id\":2,\"category\":{\"id\":116,\"sub_cat\":[{\"id\":117,\"sub_cat\":[],\"name\":\"参鲍\",\"code\":\"cb\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":118,\"sub_cat\":[],\"name\":\"鱼\",\"code\":\"yu\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":119,\"sub_cat\":[],\"name\":\"虾\",\"code\":\"xia\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":120,\"sub_cat\":[],\"name\":\"蟹/贝\",\"code\":\"xb\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116}],\"name\":\"海鲜水产\",\"code\":\"hxsc\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/2_P_1448945810202.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/15_P_1448947257324.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/2_20170719161405_249.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/9_P_1448944791617.jpg\"}],\"goods_sn\":\"sssss\",\"name\":\"田然牛肉大黄瓜条生鲜牛肉冷冻真空黄牛\",\"click_num\":5885,\"sold_num\":100,\"fav_num\":0,\"goods_num\":-6,\"market_price\":106.0,\"shop_price\":88.0,\"goods_brief\":\"前腿+后腿+羊排共8斤，原生态大山放牧羊羔，曾经的皇室贡品，央视推荐，2005年北京招待全球财金首脑。五层专用包装箱+真空包装+冰袋+保鲜箱+顺丰冷链发货，路途保质期8天\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/> </p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/> </p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/> </p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/2_P_1448945810202.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:00\"}\n",
      "{\"id\":11,\"category\":{\"id\":111,\"sub_cat\":[{\"id\":112,\"sub_cat\":[],\"name\":\"羊肉\",\"code\":\"yr\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":111},{\"id\":113,\"sub_cat\":[],\"name\":\"禽类\",\"code\":\"ql\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":111},{\"id\":114,\"sub_cat\":[],\"name\":\"猪肉\",\"code\":\"zr\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":111},{\"id\":115,\"sub_cat\":[],\"name\":\"牛肉\",\"code\":\"nr\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":111}],\"name\":\"精品肉类\",\"code\":\"jprl\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/3_P_1448945490837.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/3_P_1448945490084.jpg\"}],\"goods_sn\":\"\",\"name\":\"澳洲进口牛尾巴300g新鲜肥牛肉\",\"click_num\":4107,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":306.0,\"shop_price\":255.0,\"goods_brief\":\"新鲜羊羔肉整只共15斤，原生态大山放牧羊羔，曾经的皇室贡品，央视推荐，2005年北京招待全球财金首脑。五层专用包装箱+真空包装+冰袋+保鲜箱+顺丰冷链发货，路途保质期8天\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/3_P_1448945490837.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":9,\"category\":{\"id\":131,\"sub_cat\":[],\"name\":\"菌菇类\",\"code\":\"jgl\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:34\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/6_P_1448945167279.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/6_P_1448945167015.jpg\"}],\"goods_sn\":\"\",\"name\":\"潮香村澳洲进口牛排家庭团购套餐20片\",\"click_num\":4119,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":239.0,\"shop_price\":199.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/6_P_1448945167279.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "{\"id\":12,\"category\":{\"id\":116,\"sub_cat\":[{\"id\":117,\"sub_cat\":[],\"name\":\"参鲍\",\"code\":\"cb\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":118,\"sub_cat\":[],\"name\":\"鱼\",\"code\":\"yu\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":119,\"sub_cat\":[],\"name\":\"虾\",\"code\":\"xia\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116},{\"id\":120,\"sub_cat\":[],\"name\":\"蟹/贝\",\"code\":\"xb\",\"desc\":\"\",\"category_type\":3,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":116}],\"name\":\"海鲜水产\",\"code\":\"hxsc\",\"desc\":\"\",\"category_type\":2,\"is_tab\":false,\"add_time\":\"2017-07-29T18:56:33\",\"parent_category\":110},\"images\":[{\"image\":\"http://shop.projectsedu.com/media/goods/images/48_P_1448943988970.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/48_P_1448943988898.jpg\"},{\"image\":\"http://shop.projectsedu.com/media/goods/images/48_P_1448943988439.jpg\"}],\"goods_sn\":\"\",\"name\":\"新疆巴尔鲁克生鲜牛排眼肉牛扒1200g\",\"click_num\":3979,\"sold_num\":0,\"fav_num\":0,\"goods_num\":0,\"market_price\":126.0,\"shop_price\":88.0,\"goods_brief\":\"\",\"goods_desc\":\"<p><img src=\\\"/media/goods/images/2_20170719161405_249.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161414_628.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p><p><img src=\\\"/media/goods/images/2_20170719161435_381.jpg\\\" title=\\\"\\\" alt=\\\"2.jpg\\\"/></p>\",\"ship_free\":true,\"goods_front_image\":\"http://shop.projectsedu.com/media/goods/images/48_P_1448943988970.jpg\",\"is_new\":false,\"is_hot\":false,\"add_time\":\"2017-07-31T23:53:53\"}\n",
      "0.7235779762268066\n"
     ]
    }
   ],
   "source": [
    "#1. epoll并不代表一定比select好\n",
    "# 在并发高的情况下，连接活跃度不是很高， epoll比select\n",
    "# 并发性不高，同时连接很活跃， select比epoll好\n",
    "\n",
    "#通过非阻塞io实现http请求\n",
    "# select + 回调 + 事件循环\n",
    "#  并发性高\n",
    "# 使用单线程\n",
    "\n",
    "import socket\n",
    "from urllib.parse import urlparse\n",
    "from selectors import DefaultSelector, EVENT_READ, EVENT_WRITE\n",
    "\n",
    "\n",
    "selector = DefaultSelector()\n",
    "#使用select完成http请求\n",
    "urls = []\n",
    "stop = False\n",
    "\n",
    "\n",
    "class Fetcher:\n",
    "    def connected(self, key):\n",
    "        selector.unregister(key.fd)\n",
    "        self.client.send(\"GET {} HTTP/1.1\\r\\nHost:{}\\r\\nConnection:close\\r\\n\\r\\n\".format(self.path, self.host).encode(\"utf8\"))\n",
    "        selector.register(self.client.fileno(), EVENT_READ, self.readable)\n",
    "\n",
    "    def readable(self, key):\n",
    "        d = self.client.recv(1024)\n",
    "        if d:\n",
    "            self.data += d\n",
    "        else:\n",
    "            selector.unregister(key.fd)\n",
    "            data = self.data.decode(\"utf8\")\n",
    "            html_data = data.split(\"\\r\\n\\r\\n\")[1]\n",
    "            print(html_data)\n",
    "            self.client.close()\n",
    "            urls.remove(self.spider_url)\n",
    "            if not urls:\n",
    "                global stop\n",
    "                stop = True\n",
    "\n",
    "    def get_url(self, url):\n",
    "        self.spider_url = url\n",
    "        url = urlparse(url)\n",
    "        self.host = url.netloc\n",
    "        self.path = url.path\n",
    "        self.data = b\"\"\n",
    "        if self.path == \"\":\n",
    "            self.path = \"/\"\n",
    "\n",
    "        # 建立socket连接\n",
    "        self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",
    "        self.client.setblocking(False)\n",
    "\n",
    "        try:\n",
    "            self.client.connect((self.host, 80))  # 阻塞不会消耗cpu\n",
    "        except BlockingIOError as e:\n",
    "            pass\n",
    "\n",
    "        #注册\n",
    "        selector.register(self.client.fileno(), EVENT_WRITE, self.connected)\n",
    "\n",
    "\n",
    "def loop():\n",
    "    #事件循环，不停的请求socket的状态并调用对应的回调函数\n",
    "    #1. select本身是不支持register模式\n",
    "    #2. socket状态变化以后的回调是由程序员完成的\n",
    "    while not stop:\n",
    "        ready = selector.select()\n",
    "        for key, mask in ready:\n",
    "            call_back = key.data\n",
    "            call_back(key)\n",
    "    #回调+事件循环+select(poll\\epoll)\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    fetcher = Fetcher()\n",
    "    import time\n",
    "    start_time = time.time()\n",
    "    for url in range(20):\n",
    "        url = \"http://shop.projectsedu.com/goods/{}/\".format(url)\n",
    "        urls.append(url)\n",
    "        fetcher = Fetcher()\n",
    "        fetcher.get_url(url)\n",
    "    loop()\n",
    "    print(time.time()-start_time)\n",
    "\n",
    "# def get_url(url):\n",
    "#     #通过socket请求html\n",
    "#     url = urlparse(url)\n",
    "#     host = url.netloc\n",
    "#     path = url.path\n",
    "#     if path == \"\":\n",
    "#         path = \"/\"\n",
    "# \n",
    "#     #建立socket连接\n",
    "#     client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",
    "#     client.setblocking(False)\n",
    "#     try:\n",
    "#         client.connect((host, 80)) #阻塞不会消耗cpu\n",
    "#     except BlockingIOError as e:\n",
    "#         pass\n",
    "# \n",
    "#     #不停的询问连接是否建立好， 需要while循环不停的去检查状态\n",
    "#     #做计算任务或者再次发起其他的连接请求\n",
    "# \n",
    "#     while True:\n",
    "#         try:\n",
    "#             client.send(\"GET {} HTTP/1.1\\r\\nHost:{}\\r\\nConnection:close\\r\\n\\r\\n\".format(path, host).encode(\"utf8\"))\n",
    "#             break\n",
    "#         except OSError as e:\n",
    "#             pass\n",
    "# \n",
    "# \n",
    "#     data = b\"\"\n",
    "#     while True:\n",
    "#         try:\n",
    "#             d = client.recv(1024)\n",
    "#         except BlockingIOError as e:\n",
    "#             continue\n",
    "#         if d:\n",
    "#             data += d\n",
    "#         else:\n",
    "#             break\n",
    "# \n",
    "#     data = data.decode(\"utf8\")\n",
    "#     html_data = data.split(\"\\r\\n\\r\\n\")[1]\n",
    "#     print(html_data)\n",
    "#     client.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
